<?php

namespace Addons\CentralControl\Controller\api;

use Addons\CentralControl\Services\CentralService;
use Addons\CentralControl\Services\ModbusService;
use Common\ApiController;
use Common\Helpers\DebugHelper;
use Hyperf\HttpServer\Annotation\AutoController;

#[AutoController(prefix: '{project_sn}/centralControl/zyj')]
class ZyjController extends  ApiController
{
    function deviceInfo(): array
    {
        try {
            DebugHelper::consoleWrite('设备信息-deviceInfo');

            $clientid = $this->request->input('clientid');
            $Res = CentralService::getDevicedByClientId($clientid);
            DebugHelper::consoleWrite('设备信息',$Res);
            return $this->writeJson(200, $Res, '获取设备信息成功');

        }catch (\Exception $e){
            DebugHelper::consoleWrite('设备信息-deviceInfo-error',$e->getMessage());
        }
        return $this->writeJson(500, [], '获取设备信息失败');
    }

    function tonum()
    {
        $num = $this->request->input('num');
        $ModbusService = new ModbusService();
        $Res = $ModbusService->buildModbusCommandNum($num);
        return $this->writeJson(200, [
            'command'=>$Res
        ], '获取指令成功');
    }
}